package com.ebelter.myehc.ui.activitys;



import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebelter.btcomlib.models.eventbus.CommonEventBus;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.myehc.R;
import com.ebelter.myehc.ui.fragments.historys.H_BC_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_BO_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_CH_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_Sports_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_Tiwen_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_UA_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_XueTang_Fragment;
import com.ebelter.myehc.ui.fragments.historys.H_XueYa_Fragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_BRA;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_NIAOSUAN;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_TIWEN;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_TIZHICHENG;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_XUETANG;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_XUEYA;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_XUEYANG;
import static com.ebelter.myehc.ui.activitys.TrendActivity.Trend_ZONGDANGUCHUN;

public class HistoryActivity extends EhcBaseActivity implements View.OnClickListener {

    public static final String TAG = "HistoryActivity";
    public static final String KEY = "HistoryActivity_KEY";


    private int currentModifyType = -1;



    private ImageView top_left_iv;
    private TextView top_title_tv;
    private View toptitle_buttom_line_view;


    @Override
    protected int loadLayoutById() {
        return R.layout.activity_history;
    }


    @Override
    protected void initView() {
        super.initView();
        currentModifyType = getIntent().getIntExtra(KEY,-1);
        if (currentModifyType==-1){
            throw new RuntimeException("参数不对异常");
        }
        EventBus.getDefault().register(this);
        LogUtils.i(TAG,"initView------currentModifyType = "+currentModifyType);
        FV();
        setListener();
        replaceFragment(getFragmentByType(currentModifyType),R.id.history_contain_f);

    }


    private void setListener() {
        top_left_iv.setOnClickListener(this);
    }

    private void FV() {
        top_left_iv=findViewById(R.id.top_left_iv);
        TextView top_right_tv = findViewById(R.id.m_righttitle_tv);
        ViewUtils.hideView(top_right_tv);
        top_title_tv=findViewById(R.id.m_title_tv);
        toptitle_buttom_line_view=findViewById(R.id.toptitle_buttom_line_view);
    }




    public Fragment getFragmentByType(int currentType){
        Fragment fragment = null;
        String title = "";
        if (currentModifyType==Trend_XUEYA){
            fragment=new H_XueYa_Fragment();
            title=getString_(R.string.xylb);
        } else if (currentModifyType==Trend_XUEYANG){
            title=getString_(R.string.xybhdlb);
            fragment=new H_BO_Fragment();
        }else if (currentModifyType==Trend_TIWEN){
            title=getString_(R.string.twlb);
            fragment=new H_Tiwen_Fragment();
        }else if (currentModifyType==Trend_XUETANG){
            title=getString_(R.string.xtlb);
            fragment=new H_XueTang_Fragment();
        }else if (currentModifyType==Trend_NIAOSUAN){
            title=getString_(R.string.nslb);
            fragment=new H_UA_Fragment();
        }else if (currentModifyType==Trend_ZONGDANGUCHUN){
            title=getString_(R.string.zdgchlb);
            fragment=new H_CH_Fragment();
        }else if (currentModifyType==Trend_TIZHICHENG){
            title=getString_(R.string.tzhchlb);
            fragment=new H_BC_Fragment();
        }else if (currentModifyType==Trend_BRA){
            title=getString_(R.string.dllb);
            fragment=new H_Sports_Fragment();
        }
        top_title_tv.setText(title);
        return fragment;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(CommonEventBus event) {
        if (!event.whichReceive.contains(TAG)) {
            return;
        }
        LogUtils.i(TAG, "HistoryActivity--onEventMainThread接收到CommonEventBus信息--" + event.toString());

        if (event.cmd == 0){
            ViewUtils.goneView(toptitle_buttom_line_view);
        }else if (event.cmd==1){
            ViewUtils.displayView(toptitle_buttom_line_view);
        }


    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id==R.id.top_left_iv){
            finish();
        }
    }


}
